package org.example.springboot.dao;

import org.apache.ibatis.annotations.*;
import org.example.springboot.model.Suppliers;

import java.util.List;

@Mapper
public interface SuppliersMapper {
    @Insert("insert into suppliers(supplier_name, address, website, status, bank_name, bank_account, contact_person, contact_phone, description) values(#{supplierName},#{address},#{website}, #{status},#{bankName},#{bankAccount}, #{contactPerson},#{contactPhone},#{description})")
    int insertSuppliers(@Param("supplierName") String supplierName,@Param("address") String address,@Param("website") String website,@Param("status") String status,@Param("bankName") String bankName,@Param("bankAccount") String bankAccount,@Param("contactPerson") String contactPerson,@Param("contactPhone") String contactPhone,@Param("description") String description);

    @Select("select * from suppliers")
    List<Suppliers> getAllSuppliers();

    @Select("select supplier_name from suppliers ")
    List<Suppliers> getAllSuppliersName();

    @Select("select * from suppliers " + "where supplier_name like CONCAT('%', #{keyword}, '%') " + "or contact_person like CONCAT('%', #{keyword}, '%')")
    List<Suppliers> findSuppliers(@Param("keyword")String keyword);

    @Select("select * from suppliers where id = #{id}")
    Suppliers findSuppliersById(@Param("id")int id);

    @Delete("delete from suppliers where id = #{id}")
    void deleteById(@Param("id")int id);


}
